<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2018/11/20
 * Time: 17:32
 */

namespace common\sources\write\buyuser;

use common\models\craftsman\BuyUserAccount;
use Yii;

class BuyUserAcountAccess implements IBuyUserAcountAccess
{
   public function addUserAccount($data)
   {
       return Yii::$app->db->createCommand()->insert('buyuser_account', [
           'buy_id' =>  $data['buy_id'],
           'remain_funds' => $data['remain_funds'],
           'remail_golds' => $data['remail_golds'],
           'freezing_funds' => $data['freezing_funds'],
           'freezing_golds' => $data['freezing_golds'],
           'income_golds' => $data['income_golds'],
           'create_time' => time()
       ])->execute();
   }
   //修改本金和佣金记录
   public function  modifyUserAccount($data)
   {
       $sql = 'UPDATE ' . BuyUserAccount::tableName() . ' SET remain_funds = :remain_funds,remail_golds = :remail_golds,update_time = :update_time WHERE buy_id = :buy_id ';
       return Yii::$app->db->createCommand($sql)
           ->bindValues([
               ':remain_funds' => $data['remain_funds'],
               ':remail_golds' => $data['remail_golds'],
               ':update_time' => time(),
               ':buy_id' => $data['buy_id'],
           ])->execute();
   }
    //修改本金和冻结本金
   public function  modifyPrincipalUserAccount($data)
   {
       $sql = 'UPDATE ' . BuyUserAccount::tableName() . ' SET remain_funds = :remain_funds,freezing_funds = :freezing_funds,update_time = :update_time WHERE buy_id = :buy_id ';
       return Yii::$app->db->createCommand($sql)
           ->bindValues([
               ':remain_funds' => $data['remain_funds'],
               ':freezing_funds' => $data['freezing_funds'],
               ':update_time' => time(),
               ':buy_id' => $data['buy_id'],
           ])->execute();
   }
   //修改可用花椒和冻结花椒
   public function modifyPepperUserAccount($data)
   {
       $sql = 'UPDATE ' . BuyUserAccount::tableName() . ' SET remail_golds = :remail_golds,freezing_golds = :freezing_golds,update_time = :update_time WHERE buy_id = :buy_id ';
       return Yii::$app->db->createCommand($sql)
           ->bindValues([
               ':remail_golds' => $data['remail_golds'],
               ':freezing_golds' => $data['freezing_golds'],
               ':update_time' => time(),
               ':buy_id' => $data['buy_id'],
           ])->execute();
   }
   //修改收益花椒和花椒余额
   public function modifyIncomeUserAccount($data)
   {
       $sql = 'UPDATE ' . BuyUserAccount::tableName() . ' SET remail_golds = :remail_golds,income_golds = :income_golds,update_time = :update_time WHERE buy_id = :buy_id ';
       return Yii::$app->db->createCommand($sql)
           ->bindValues([
               ':remail_golds' => $data['remail_golds'],
               ':income_golds' => $data['income_golds'],
               ':update_time' => time(),
               ':buy_id' => $data['buy_id'],
           ])->execute();
   }
   //修改本金余额
    public function modifyBuyUserAccount($data)
    {
        $sql = 'UPDATE ' . BuyUserAccount::tableName() . ' SET remail_golds = :remail_golds ,update_time = :update_time WHERE buy_id = :buy_id ';
        return Yii::$app->db->createCommand($sql)
            ->bindValues([
                ':remail_golds' => $data['remail_golds'],
                ':update_time' => time(),
                ':buy_id' => $data['buy_id'],
            ])->execute();
    }
}